/**
 * Created by admin on 2017/8/9.
 */
define(['app', 'filters/filters'],function(app){
    app.register.controller('myCoursenew', function($scope, $http, $state, $sce,$stateParams,$rootScope, $confirm){
        $scope.loading_show = true;
        $scope.cate_id = $stateParams.cate_id;
        $scope.specialty_id = $stateParams.specialty_id;
        $scope.load = {
            _getMajorinfo: function(){  //专业班分类
                $http({
                    url: app._baseUrl + 'Qy/specialty/lists&cate_id=' + $scope.cate_id,
                    method: 'GET',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function(responed){
                    if(responed.success){
                        $scope.loading_show = false;
                        $scope.majorInfo = responed.data;
                    }


                });

            },
            _getMajorDetail: function(e,index){  //专业详情
                if(e){
                    if(e.lock_status==1){
                        $(".con_l2 a").removeClass("active");//其他leftList移除active,当前添加active
                        $(".con_l2 a").eq(index).addClass("active");
                        $http({//请求初级、中级、高级各对应的课程
                            url: app._baseUrl + 'Qy/Specialty/info&specialty_id=' + e.specialty_id,
                            method: 'GET',
                            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                        }).success(function(responed){
                            if(responed.success){
                                $scope.loading_show = false;
                                $scope.majorDetail = responed.data.curriculum_list;
                                $scope.top_banner = responed.data.top_banner;
                                $scope.specialty_id = responed.data.specialty_id;
                            }

                        });
                    }else{//不可以跳转，后续加弹窗
                        $scope.sec = 5;
                        var interval = setInterval(function() {//设置定时器
                            if($scope.sec > 0) {
                                $scope.sec--;
                                $scope.tipShowzy = true;//提示显示
                                $('.tool_zy').fadeIn(600);
                            } else {
                                clearInterval(interval);
                                $scope.tipShowzy = true;
                                $('.tool_zy').fadeOut(600);
                            }
                            $scope.$digest();//脏数据检验
                        }, 500)
                    }
                }else{
                    $http({//请求初级、中级、高级各对应的课程
                        url: app._baseUrl + 'Qy/Specialty/info&specialty_id=' + $scope.specialty_id,
                        method: 'GET',
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                    }).success(function(responed){
                        if(responed.success){
                            $scope.loading_show = false;
                            $scope.majorDetail = responed.data.curriculum_list;
                            $scope.specialty_id = responed.data.specialty_id;
                            $scope.top_banner = responed.data.top_banner;
                        }

                    });
                }

            },
            init: function(){
                $scope.majorInfo = [];
                this._getMajorinfo && this._getMajorinfo();
                $scope.majorDetail = [];
                this._getMajorDetail && this._getMajorDetail();
            }
        };
        $scope.load.init && $scope.load.init();
        //给左边列表一个点击事件
        // $scope.leftList = function(){
        //
        // }
        //课程一个点击事件
        $scope.tCourse = function(major){
            //app.trainCourse({curriculum_id:major.curriculum_id})
            // if(major.lock_status==1||major.lock_status==2){//可跳转，未加锁
                var url = $state.href('app.trainCourse',{curriculum_id:major.curriculum_id});
                window.open(url,'_blank');
            // }else{//不可以跳转，后续加弹窗

            // }
        };

        //温馨提示
        $scope.tipPop = function() {
            $scope.tipModal.show();
        };

        // 弹框
        // 编辑课程
        $scope.tipModal = {
            isShow: false,
            title: '温馨提示',
            data: {},
            confirm: function() {
                this.hide()
            },
            cancel: function() {
                this.hide()
            },
            hide: function() {
                this.isShow = false;
            },
            show: function() {
                this.isShow = true;
            }
        }
    })
})